package com.ruoyi.system.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.system.domain.SysVideo;
import com.ruoyi.system.service.ISysVideoService;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/video")
public class SysVideoController extends BaseController {
    @Autowired
    private ISysVideoService sysVideoService;

    /**
     * 获取视频信息列表
     */
    @GetMapping("/list")
    public AjaxResult list(SysVideo sysVideo) {
        startPage();
        List<SysVideo> list = sysVideoService.selectVideoList(sysVideo);
        return success(list);
    }

    /**
     * 导出视频信息列表
     */
    @GetMapping("/export")
    public void export(HttpServletResponse response, SysVideo sysVideo) {
        List<SysVideo> list = sysVideoService.selectVideoList(sysVideo);
        ExcelUtil<SysVideo> util = new ExcelUtil<>(SysVideo.class);
        util.exportExcel(response, list, "视频数据");
    }

    /**
     * 获取视频信息详细信息
     */
    @GetMapping(value = "/{videoId}")
    public AjaxResult getInfo(@PathVariable("videoId") Long videoId) {
        return AjaxResult.success(sysVideoService.selectVideoById(videoId));
    }

    /**
     * 新增视频信息
     */
    @PostMapping
    public AjaxResult add(@RequestBody SysVideo sysVideo) {
        return toAjax(sysVideoService.insertVideo(sysVideo));
    }

    /**
     * 修改视频信息
     */
    @PutMapping
    public AjaxResult edit(@RequestBody SysVideo sysVideo) {
        return toAjax(sysVideoService.updateVideo(sysVideo));
    }

    /**
     * 删除视频信息
     */
    @DeleteMapping("/{videoIds}")
    public AjaxResult remove(@PathVariable Long[] videoIds) {
        return toAjax(sysVideoService.deleteVideoByIds(videoIds));
    }
}